<?php

namespace App\Http\Resources\Apps;

use Illuminate\Http\Resources\Json\JsonResource;

class OrderResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $sale_user = UserInfoResource::make($this['sale_user']);
        return [
            'order_no'  => $this['order_no'],
            'amount'    => $this['amount'],
            'integral'  => $this['integral'],
            'name'      => $this['product']['name'],
            'preview'   => $this['product']['preview'],
            'sale_user' => collect($sale_user)->only(['mobile','nickname','invite']),
            'bank'      => $sale_user['bank'] ? collect($sale_user)->get('bank') : (object) [],
            'voucher'   => $this['voucher'],
            'status'    => $this['status'],
            'created_at'=> $this['created_at'],
        ];
    }
}
